package org.wxd.ms.stu.service.api.rest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import org.wxd.ms.stu.service.domain.User;
import org.wxd.ms.stu.service.jpa.UserRepository;

import javax.annotation.Resource;

/**
 * Created by wangxd on 2017/6/9.
 */
@RestController
public class UserCtl {
    private static final Logger LOGGER = LoggerFactory.getLogger(UserCtl.class);

    @Resource
    private UserRepository repository;


    @PostMapping("/user/save")
    public Long save(@RequestBody User user) {
        LOGGER.info("save user [{}]",user);
        repository.save(user);
        return user.getId();
    }


    @GetMapping("/user/{id}")
    public User findById(@PathVariable("id") Long id) {
        LOGGER.info("the user id is [{}]",id);
        return repository.findOne(id);
    }
}
